package com.liu.service.impl;//

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liu.dao.ClearGoodsDao;
import com.liu.entity.ClearGoods;
import com.liu.service.intf.ClearGoodsService;
import com.liu.vo.PageBeanJson;
import com.liu.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

//                       .::::.
//                     .::::::::.
//                    :::::::::::
//                 ..:::::::::::'
//              '::::::::::::'
//                .::::::::::
//           '::::::::::::::..
//                ..::::::::::::.
//              ``::::::::::::::::
//               ::::``:::::::::'        .:::.
//              ::::'   ':::::'       .::::::::.
//            .::::'      ::::     .:::::::'::::.
//           .:::'       :::::  .:::::::::' ':::::.
//          .::'        :::::.:::::::::'      ':::::.
//         .::'         ::::::::::::::'         ``::::.
//     ...:::           ::::::::::::'              ``::.
//    ```` ':.          ':::::::::'                  ::::..
//                       '.:::::'                    ':'````..
@Service
public class ClearGoodsImpl implements ClearGoodsService {
    @Autowired
    private ClearGoodsDao dao;
    @Override
    public R othersInsert(ClearGoods clearGoods) {
        if (dao.insert(clearGoods) > 0) {
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public PageBeanJson pageQuery(int page, int limit) {
        PageHelper.startPage(page,limit);
        PageInfo<ClearGoods> pageInfo = new PageInfo<>(dao.selectAll());
        return PageBeanJson.bean(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public PageBeanJson NameQuery(String name, int size, int limit) {
        if(StringUtils.hasLength(name)){
            name = "%"+name+"%";
        }else{
            name = null;
        }
        PageHelper.startPage(size,limit);
        PageInfo<ClearGoods> pageInfo = new PageInfo<>(dao.selectByName(name));
        return PageBeanJson.bean(pageInfo.getTotal(),pageInfo.getList());
    }

    @Override
    public R ohtersUpdate(int id) {
        if(dao.update(id)>0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public R othersDelete(int id) {
        if(dao.delete(id)>0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public R partDelete(int[] ids) {
        if(dao.partDelete(ids)>0){
            return R.ok();
        }else{
            return R.fail();
        }
    }
}
